package com.mapper.helping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.domain.Issue;
import com.domain.Label;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 大忽悠
 * @since 2022年02月08日
 */
public interface LabelMapper extends BaseMapper<Label> {

    @Select("SELECT l.* FROM label  l\n" +
            "INNER JOIN label_with_issue lwi\n" +
            "ON l.id=lwi.label_id\n" +
            "WHERE lwi.issue_id=#{issue_id}  ORDER BY l.id DESC")
    List<Label> listAllLabelsWithTargetIssue(@Param("issue_id") Integer issue_id);

    @Select("SELECT i.* FROM issue i \n" +
            "INNER JOIN label_with_issue lwi\n" +
            "ON lwi.issue_id=i.id\n" +
            "INNER JOIN label l\n" +
            "ON l.id=lwi.label_id\n" +
            "WHERE l.content LIKE '%${keyWord}%'"+
             "ORDER BY i.update_time DESC")
    List<Issue> selectVagueByLabelContent(Page<Issue> page, @Param("keyWord") String keyWord);

    @Select("SELECT i.* FROM issue i \n" +
            "INNER JOIN label_with_issue lwi\n" +
            "ON lwi.issue_id=i.id\n" +
            "INNER JOIN label l\n" +
            "ON l.id=lwi.label_id\n" +
            "WHERE l.id=#{label_id}\n" +
            "ORDER BY i.update_time DESC")
    List<Issue> getIssuesUnderTargetLabel(@Param("label_id") Integer label_id,Page<Issue> page);


    @Update("UPDATE label SET hot=hot-#{hot}")
    boolean reduceHot(@Param("hot") Integer label_hour_reduce_hot);

    @Update("UPDATE label SET is_audited=1 where id=#{label_id}")
    Boolean passLabel(@Param("label_id") Integer label_id);
}
